package cn.itsource;

import cn.itsource.domain.org.Shop;
import cn.itsource.mapper.ShopMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

//@Component
public class TaskShopCheck {
    @Autowired
    ShopMapper shopMapper;

    @Scheduled(cron = "0 0 0 1/1 * ? ")
    public void Check(){
        //这里是我们的业务逻辑
        List<Shop> shops = shopMapper.selectList(null);
        shops.stream().filter(shop -> shop.getValidTime().before(new Date())).forEach(shop -> {
            //这里全部都是过期的数据
            shop.setStatus(Boolean.FALSE);
            shopMapper.updateById(shop);
        });
    }

    @Scheduled(cron = "0/5 * * * * ? ")
    public void Check1(){
        //这里是我们的业务逻辑
        System.out.println("执行定时任务拉,五秒执行一次");
    }
}
